#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void main(void){

    int a, b, c;

    //clock_t s;
    time_t s;

    struct timespec start, finish;

    int ans;

    srand(time(NULL));

    a = 1 + rand() % 10;
    b = 1 + rand() % 10;
    c = 1 + rand() % 10;

    s = time(NULL);

    clock_gettime(CLOCK_REALTIME, &start);


    while (1) {
        printf("%d + %d + %d = ", a, b, c);
        scanf("%d", &ans);

        getchar(); //如果非数字造成死循环

        if (a+b+c == ans) {
            break;
        }

        printf("\n回答错误! 你的回答:%d\n", ans);
    }

    //double req_time = (double)(time(NULL) - s);

    clock_gettime(CLOCK_REALTIME, &finish);

    long seconds = finish.tv_sec - start.tv_sec;
    long ns = finish.tv_nsec - start.tv_nsec;

    if (start.tv_nsec > finish.tv_nsec) {
        --seconds;
        ns += 1000000000;
    }

    double req_time = (double)seconds + (double)ns/1000000000;

    printf("回答共用去时间:%.2f秒\n", req_time);

    if (req_time > 15) {
        puts("花太多时间了!");

    } else if (req_time > 5) {
        puts("还行吧!");

    } else if (req_time > 3) {
        puts("不错!");

    } else {
        puts("真快!");
    }

}
